package com.easyattendance.model;

import java.util.Comparator;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "TBL_MATERIAL_CLASS")
@IdClass(MaterialClassPK.class)
public class MaterialClass implements Comparable<MaterialClass>{
	
	@Id
	@GenericGenerator(name="material_id",strategy="foreign")
	@Column(name = "material_id",length=10,nullable=false)
	private String material_id;

	@Id
	@GenericGenerator(name="class_id",strategy="foreign")
	@Column(name="class_id",nullable=true,length=15)
	private String class_id;
	
	@Id
	@GenericGenerator(name="subject_id",strategy="foreign")
	@Column(name="subject_id",nullable=true,length=6)
	private String subject_id;
	
	/* Many to one mappings of MaterialClass */

	@ManyToOne
	@JoinColumn(name = "teacher_id",nullable=true)
	private Teacher teacher;

	@ManyToOne
	@JoinColumn(name = "class_id",insertable=false,updatable=false,nullable=true)
	private Class classObj;

	@ManyToOne
	@JoinColumn(name = "subject_id",insertable=false,updatable=false,nullable=true)
	private Subject subject;
	
	@ManyToOne
	@JoinColumn(name = "material_id",insertable=false,updatable=false)
	private Material material;
	
	public MaterialClass()
	{
		
	}

	public MaterialClass(String material_id, String class_id, String subject_id) {
		super();
		this.material_id = material_id;
		this.class_id = class_id;
		this.subject_id = subject_id;
	
	}

	public String getMaterial_id() {
		return material_id;
	}

	public void setMaterial_id(String material_id) {
		this.material_id = material_id;
	}

	public String getClass_id() {
		return class_id;
	}

	public void setClass_id(String class_id) {
		this.class_id = class_id;
	}

	public String getSubject_id() {
		return subject_id;
	}

	public void setSubject_id(String subject_id) {
		this.subject_id = subject_id;
	}

	public Teacher getTeacher() {
		return teacher;
	}

	public void setTeacher(Teacher teacher) {
		this.teacher = teacher;
	}

	public Class getClassObj() {
		return classObj;
	}

	public void setClassObj(Class classObj) {
		this.classObj = classObj;
	}

	public Subject getSubject() {
		return subject;
	}

	public void setSubject(Subject subject) {
		this.subject = subject;
	}

	public Material getMaterial() {
		return material;
	}

	public void setMaterial(Material material) {
		this.material = material;
	}

	@Override
	public int compareTo(MaterialClass arg0) {
		// TODO Auto-generated method stub
		return 0;
	}
	
	/* Comparator interface to sort list of Materials by Class Id */
	   public static class SortMaterialByClass implements Comparator<MaterialClass> {

			@Override
			public int compare(MaterialClass material1, MaterialClass material2) {
				return material1.class_id.compareTo(material2.class_id);
			}
	   }


}
